package com.lucyyun.lcrpccore.server.tcp;

import cn.hutool.core.util.IdUtil;

import com.lucyyun.lcrpccore.RpcApplication;
import com.lucyyun.lcrpccore.model.RpcRequest;
import com.lucyyun.lcrpccore.model.RpcResponse;
import com.lucyyun.lcrpccore.model.ServiceMetaInfo;
import com.lucyyun.lcrpccore.protocol.ProtocolConstant;
import com.lucyyun.lcrpccore.protocol.ProtocolMessage;
import com.lucyyun.lcrpccore.protocol.ProtocolMessageSerializerEnum;
import com.lucyyun.lcrpccore.protocol.ProtocolMessageTypeEnum;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetSocket;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Vertx TCP 请求客户端
 *
 */
public class VertxTcpClient {

public void start(){
    Vertx vertx = Vertx.vertx();
    vertx.createNetClient().connect(8888,"localhost",result->{
        if (result.succeeded()){
            System.out.println("连接到 TCP server");
            io.vertx.core.net.NetSocket socket = result.result();
            socket.write("hello ,server");
            
            socket.handler(buffer -> {
                System.out.println("receive response from server "+buffer.toString());
            });
        }else {
            System.out.println("failed to connect Tcp Server");
        }
    });
}

    public static void main(String[] args) {
        new VertxTcpClient().start();
    }

}
